package com.tqfframe.website.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Tang-QiFeng on 2021/1/2
 */
public class DateUtil {

    public final static String datePattern="yyyy-MM-dd";
    public final static String timePattern="yyyy-MM-dd HH:mm:ss";

    public static Date StringToDate(String value){
        Date date=null;
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(datePattern);
        try {
            date= simpleDateFormat.parse(value);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date StringToDateTime(String value){
        Date date=null;
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(timePattern);
        try {
            date= simpleDateFormat.parse(value);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static String DateToString(Date value){
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(datePattern);
        return simpleDateFormat.format(value);
    }

    public static String DateTimeToString(Date value){
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(timePattern);
        return simpleDateFormat.format(value);
    }

    public static void main(String[] args) {
        System.out.println(StringToDateTime("2019-10-29 10:20:20"));
    }

}
